import _ from 'lodash';
import { message } from 'antd';
import { isSuccess } from '@/utils/request';
import modelType from '../constant/modelTypeConstant';

const noop = () => {};
const { time = noop, timeLog = noop, timeEnd = noop } = console;

function* getState(select, namespace) {
    return yield select(state => state[namespace]);
}

function* searchPostData(select, namespace) {
    const currentState = yield* getState(select, namespace);

    const searchCondition = {
        searchModel: currentState.searchModel,
        pagination: currentState.pagination || {
            current: 1,
            pageSize: 10
        },
        nodeCode: currentState.nodeCode
    };

    const { searchModel, pagination } = searchCondition;
    const periodStr = currentState.period || '';
    const year = periodStr.substr(0, 4);
    const month = periodStr.substr(5);

    return {
        year,
        month: month ? String(parseInt(month, 10)) : month,
        page: {
            pageNo: pagination.current,
            pageSize: pagination.pageSize
        },
        ...searchModel,
        nodeCode: searchCondition.nodeCode
    };
}

function getNewPageInfo(state, response, organizationCode) {
    const { pageSize, total, pageNo: current, rows: dataSource } = response.data;

    const pagination = {
        ...state.pagination,
        pageSize: pageSize || 10,
        current: current || 1,
        total
    };

    return {
        dataSource: dataSource && dataSource.map(item => ({
            ...item,
            organizationCode
        })),
        pagination
    };
}

function delay (ms) {
    return new Promise(resolve => {
        setTimeout(resolve, ms);
    });
}


const shareNamespace = 'recheckSharedModel';
const recheckModel = (
    namespace,
    {
        latestSalaryYearMonth,
        getCheckButtons,
        getLastSysOperationSearchInfo,
        queryTableBodyData,
        queryTableHeadData,
        queryItemCheckWarn,
        sendSalaryPayroll,
        applyPayment,
        approveSubmit,
        passCheckBatch,
        updateData,
        postponeNextMonth,
        excelExport,
        getSalaryPayrollItems,
        reject,
        batchReject,
        cancelCheck,
        passCheck
    }
) => ({
    namespace,
    state: {
        period: null,
        searchModel: {
            downAbnormalTipIndex: 5,
            upAbnormalTipIndex: 5,
            salaryRateKpiInd: 1
        },
        checkButtonList: [],

        tableLoading: false,
        stepLoading: false, // 判断stepList套件是否获取数据
        rowKey: 'id',
        pagination: {
            current: 1,
            pageSize: 10
        },
        tableHeader: [],
        dataSource: [],
        selectedRows: [],

        modalVisible: false,
        rejectLoading: false,
        payrollModalVisible: false,
        currentRecord: null,
        // 薪资单细项信息
        payRollItems: [],
        nodeCode: null
    },
    reducers: {
        [modelType.SET_MULTI_STORE](state, action) {
            return {
                ...state,
                ...action.payload
            };
        },

        [modelType.RESET_STORE](state, action) {
            return {
                ...state,
                checkButtonList: [],
                tableHeader: [],
                selectedRows: [],
                period: null,
                dataSource: [],
                footerSource: null,
                pagination: {
                    current: 1,
                    pageSize: 10
                },
                searchModel: {
                    downAbnormalTipIndex: 5,
                    upAbnormalTipIndex: 5,
                    salaryRateKpiInd: 1,
                    ...action.payload
                }
            };
        },

        [modelType.INIT_STORE](state) {
            return {
                ...state,
                checkButtonList: [],
                tableHeader: [],
                selectedRows: [],
                period: null,
                dataSource: [],
                footerSource: null,
                pagination: {
                    current: 1,
                    pageSize: 10
                }
            };
        },

        [modelType.SET_LOADING](state, action) {
            return {
                ...state,
                ...action.payload
            };
        },
        /**
         * 更变月份
         * @param action.payload 月份
         */
        [modelType.SET_PERIOD](state, action) {
            const { payload: period } = action;

            return {
                ...state,
                period
            };
        },

        [modelType.SET_SEARCH_CONDITION](state, action) {
            const { searchModel } = state;
            return {
                ...state,
                searchModel: {
                    ...searchModel,
                    ...action.payload
                }
            };
        },

        [modelType.SET_PAGE_INFO](state, action) {
            const { searchModel } = state
            const { organizationCode } = searchModel
            const { pageSize, total, pageNo: current, rows: dataSource } = action.payload.data;

            const pagination = {
                ...state.pagination,
                pageSize: pageSize || 10,
                current: current || 1,
                total
            };

            return {
                ...state,
                dataSource: dataSource && dataSource.map(item => ({
                        ...item,
                        organizationCode
                })),
                pagination
            };
        },

        [modelType.SET_PAGINATION](state, action) {
            const pagination = {
                ...state.pagination,
                current: action.payload.current || state.pagination.current,
                pageSize: action.payload.pageSize || state.pagination.pageSize
            };

            return {
                ...state,
                pagination
            };
        },

        [modelType.SET_TABLE_HEADER](state, action) {
            return {
                ...state,
                tableHeader: action.payload
            };
        },

        [modelType.SET_SELECTED_ROW](state, action) {
            return {
                ...state,
                selectedRows: action.payload
            };
        },

        [modelType.SET_MODAL_VISIBLE](state, action) {
            return {
                ...state,
                modalVisible: action.payload
            };
        },

        [modelType.SET_CURRENT_RECORD](state, action) {
            return {
                ...state,
                currentRecord: action.payload
            };
        },

        [modelType.SET_SALARY_PAYROLL_ITEMS](state, action) {
            return {
                ...state,
                payRollItems: action.payload
            };
        }
    },
    effects: {
        *[modelType.E_INIT](state, { put, call, select, all }) {
            time('初始化%c%s');
            timeLog('初始化%c%s', 'color: #FAA809;', ' -> 开始初始化');

            // 默认第一页
            const pagination = {
                ...state.pagination,
                current: 1
            };

            timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置页码1、选择行数：[]、loading: false -> 开始');
            yield put({
                type: modelType.SET_MULTI_STORE,
                payload: {
                    pagination,
                    // 默认无选中
                    selectedRows: [],
                    // 正在加载
                    tableLoading: true
                }
            });
            timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置页码1、选择行数：[]、loading: false -> 结束');

            let postData = yield* searchPostData(select, namespace);
            // 如果不是切换月份，则调用接口获取默认年月
            if (!state.payload) {
                timeLog('初始化%c%s', 'color: #FAA809;', ' -> 查询最近年份 -> 开始');
                const response = yield call(latestSalaryYearMonth, {
                    organizationCode: postData.organizationCode
                });
                timeLog('初始化%c%s', 'color: #FAA809;', ' -> 查询最近年份 -> 结束');

                if (!isSuccess(response)) {
                    message.error(`${response.msg}`);

                    timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置loading: false -> 开始');
                    yield put({
                        type: modelType.SET_LOADING,
                        payload: { tableLoading: false }
                    });
                    timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置loading: false -> 结束');

                    return;
                }
                // 未配置月模板，不请求数据
                if (!response.data.year || !response.data.month) {
                    console.log('未配置月模板，不请求数据');

                    timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置初始数据、驳回重置数据、加载状态false -> 开始');
                    yield put({
                        type: modelType.INIT_STORE
                    })

                    yield put({
                        type: 'rejectTabModel/resetData'
                    });

                    yield put({
                        type: `${shareNamespace}/${modelType.E_SHARED_STATE}`,
                        payload: {
                            sharePeriod: null
                        }
                    });

                    yield put({
                        type: modelType.SET_LOADING,
                        payload: { tableLoading: false }
                    });
                    yield put({
                        type: modelType.E_LOAD_STEP
                    });
                    timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置初始数据、驳回重置数据、加载状态false -> 结束');

                    return;
                }
                const { year, month } = response.data;

                timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置默认月份 -> 开始');
                // 设置默认月份
                yield put({
                    type: modelType.SET_PERIOD,
                    payload: `${year}-${(month < 10 ? '0' : '') + month}`
                });
                timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置默认月份 -> 结束');
            } else {
                timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置默认月份 -> 开始');
                // 设置默认月份
                yield put({
                    type: modelType.SET_PERIOD,
                    // payload: moment().from(new Date()).format('YYYY-MM')
                    payload: state.payload
                });
                timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置默认月份 -> 结束');
            }

            yield put({
                type: modelType.E_LOAD_STEP
            });

            timeLog('初始化%c%s', 'color: #FAA809;', ' -> 查询最后查询条件 -> 开始');
            const operationResponse = yield call(getLastSysOperationSearchInfo, {
                operationCode: 'salaryRecheckQueryContrast',
                organizationCode: postData.organizationCode
            });
            timeLog('初始化%c%s', 'color: #FAA809;', ' -> 查询最后查询条件 -> 结束');

            if (isSuccess(operationResponse)) {
                timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置查询条件 -> 开始');
                yield put({
                    type: modelType.SET_SEARCH_CONDITION,
                    payload: operationResponse.data
                });
                timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置查询条件 -> 开始');
            }

            postData = yield* searchPostData(select, namespace);

            yield put({
                type: 'rejectTabModel/initData',
                payload: {
                    year: postData.year,
                    month: postData.month,
                    organizationCode: postData.organizationCode
                }
            });

            timeLog('初始化%c%s', 'color: #FAA809;', ' -> 操作按钮列表获取、查询表头数据、查询表格表体数据 -> 开始');
            const [checkButtonsResponse, headerResponse, recordResponse] = yield all([
                // 操作按钮列表获取
                call(getCheckButtons, {
                    year: postData.year,
                    month: postData.month,
                    organizationCode: postData.organizationCode
                }),
                // 查询表头数据
                call(queryTableHeadData, {
                    year: postData.year,
                    month: postData.month,
                    contrastType: postData.contrastType || '1',
                    organizationCode: postData.organizationCode
                }),
                // 查询表格表体数据
                call(queryTableBodyData, postData)

            ]);
            timeLog('初始化%c%s', 'color: #FAA809;', ' -> 操作按钮列表获取、查询表头数据、查询表格表体数据 -> 结束');

            timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置按钮权限、表头数据、表体数据 -> 开始');
            const newPayload = {
                tableLoading: false
            };

            if (isSuccess(checkButtonsResponse)) {
                Object.assign(newPayload, {
                    checkButtonList: checkButtonsResponse.data
                });
            } else {
                Object.assign(newPayload, {
                    checkButtonList: []
                });
                message.error(`${checkButtonsResponse.msg}`);
            }

            if (isSuccess(headerResponse)) {
                Object.assign(newPayload, {
                    tableHeader: headerResponse.data
                });
            } else {
                Object.assign(newPayload, {
                    tableHeader: []
                });
                message.error(`${headerResponse.msg}`);
            }

            if (isSuccess(recordResponse)) {
                Object.assign(newPayload, {
                    ...getNewPageInfo(state, recordResponse, postData.organizationCode)
                });
            } else {
                Object.assign(newPayload, {
                    ...getNewPageInfo(state, { data: {} }, postData.organizationCode)
                });
                message.error(`${recordResponse.msg}`);
            }
            yield put({
                type: modelType.SET_MULTI_STORE,
                payload: newPayload
            });
            timeLog('初始化%c%s', 'color: #FAA809;', ' -> 设置按钮权限、表头数据、表体数据 -> 结束');
            timeEnd('初始化%c%s');
        },

        *[modelType.E_SEARCH](s, { put, call, select, all }) {
            time('查询%c%s');

            timeLog('查询%c%s', 'color: #FAA809;', ' -> 设置查询条件、页码：1、选择行数：[] -> 开始');
            // 设置查询条件
            if (s.payload) {
                yield put({
                    type: modelType.SET_SEARCH_CONDITION,
                    payload: s.payload
                });

                yield put({
                    type: modelType.SET_PAGINATION,
                    payload: {
                        current: 1
                    }
                });
            }

            timeLog('查询%c%s', 'color: #FAA809;', ' -> 设置查询条件、页码：1、选择行数：[] -> 结束');

            const postData = yield* searchPostData(select, namespace);

            if (!postData.year || !postData.month) {
                message.error('请选择薪资年月');
                yield put({
                    type: modelType.SET_MULTI_STORE,
                    payload: { selectedRows: [] }
                });
                return;
            }

            timeLog('查询%c%s', 'color: #FAA809;', ' -> 设置loading: true、驳回弹出框数据 -> 开始');
            yield put({
                type: modelType.SET_MULTI_STORE,
                payload: { tableLoading: true, selectedRows: [] }
            });
            yield put({
                type: 'rejectTabModel/initData',
                payload: {
                    year: postData.year,
                    month: postData.month,
                    organizationCode: postData.organizationCode
                }
            });

            timeLog('查询%c%s', 'color: #FAA809;', ' -> 请求按钮权限、表头数据、表体数据 -> 开始');
            const [checkButtonsResponse, headerResponse, response] = yield all([
                call(getCheckButtons, {
                    year: postData.year,
                    month: postData.month,
                    organizationCode: postData.organizationCode
                }),
                call(queryTableHeadData, {
                    year: postData.year,
                    month: postData.month,
                    contrastType: postData.contrastType || '1',
                    organizationCode: postData.organizationCode
                }),
                call(queryTableBodyData, postData)
            ]);
            timeLog('查询%c%s', 'color: #FAA809;', ' -> 请求按钮权限、表头数据、表体数据 -> 结束');

            const newPayload = {};

            timeLog('查询%c%s', 'color: #FAA809;', ' -> 设置按钮权限、表头数据、表体数据、加载状态：false -> 开始');
            if (isSuccess(checkButtonsResponse)) {
                Object.assign(newPayload, {
                    checkButtonList: checkButtonsResponse.data
                });
            } else {
                Object.assign(newPayload, {
                    checkButtonList: []
                });
                message.error(`${checkButtonsResponse.msg}`);
            }
            if (!isSuccess(response)) {
                message.error(`${response.msg}`);
            }

            Object.assign(newPayload, {
                ...getNewPageInfo(s, response, postData.organizationCode)
            });

            if (isSuccess(headerResponse)) {
                Object.assign(newPayload, {
                    tableHeader: headerResponse.data
                });
            } else {
                Object.assign(newPayload, {
                    tableHeader: []
                });
                message.error(`${headerResponse.msg}`);
            }

            Object.assign(newPayload, { tableLoading: false });
            yield put({
                type: modelType.SET_MULTI_STORE,
                payload: newPayload
            });
            timeLog('查询%c%s', 'color: #FAA809;', ' -> 设置按钮权限、表头数据、表体数据、加载状态：false -> 完成');
            timeEnd('查询%c%s');
        },

        *[modelType.E_TABLE_PAGE_CHANGE](state, { put }) {
            yield put({
                type: 'setPagination',
                payload: state.payload
            });
            yield put({ type: 'search' });
        },
        // 重置
        *[modelType.E_RESET](state, { put }) {
            yield put({
                type: modelType.RESET_STORE,
                payload: state.payload
            });
        },

        *[modelType.E_SEARCH_CONDITION](state, { put }) {
            yield put({
                type: modelType.SET_SEARCH_CONDITION,
                payload: state.payload
            });
            state.callback()
        },
        // 提醒细项复核
        *[modelType.E_CONFIRM_ITEM_RECHECK](s, { call }) {
            const response = yield call(queryItemCheckWarn, { salaryPayrollIdList: _.map(s.payload, 'id') });
            s.callback(response);
        },

        // 提交审批流
        *[modelType.E_APPROVE_SUBMIT](s, { call, select, put }) {
            const postData = yield* searchPostData(select, namespace);
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: true }
            });
            const response = yield call(approveSubmit, {
                year: postData.year,
                month: postData.month,
                organizationCode: postData.organizationCode
            });
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: false }
            });

            if (isSuccess(response)) {
                 yield put({
                    type: 'handleCheck',
                    payload: {
                        callback: s.callback,
                        response
                    }
                });
            } else {
                message.error(`${response.msg}`);
            }
        },

        // 下发薪资单
        *[modelType.E_SEND_SALARY_PAYROLL](s, { call, select, put }) {
            const postData = yield* searchPostData(select, namespace);
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: true }
            });
            const response = yield call(sendSalaryPayroll, {
                year: postData.year,
                month: postData.month,
                organizationCode: postData.organizationCode,
                ...s.payload
            });
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: false }
            });
            yield put({
                type: modelType.SET_MULTI_STORE,
                payload: {
                    payrollModalVisible: false
                }
            });

            yield put({
                type: 'handleCheck',
                payload: {
                    callback: s.callback,
                    response
                }
            });
        },

        // 下发薪资单弹窗
        *[modelType.E_SEND_SALARY_PAYROLL_INIT](s, { put }) {
            yield put({
                type: modelType.SET_MULTI_STORE,
                payload: {
                    payrollModalVisible: s.payload
                }
            });
        },

        // 申请付款
        *[modelType.E_APPLY_PAYMENT](s, { call, select, put }) {
            const postData = yield* searchPostData(select, namespace);
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: true }
            });
            const response = yield call(applyPayment, {
                year: postData.year,
                month: postData.month,
                organizationCode: postData.organizationCode
            });
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: false }
            });
            // s.callback(response);
            yield put({
                type: 'handleCheck',
                payload: {
                    callback: s.callback,
                    response
                }
            });
        },

        // 批量复核通过
        *[modelType.E_PASS_CHECK_BATCH](s, { call, select, put }) {
            const postData = yield* searchPostData(select, namespace);
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: true }
            });
            const response = yield call(passCheckBatch, {
                year: postData.year,
                month: postData.month,
                organizationCode: postData.organizationCode,
                salaryPayrollIdList: _.map(s.payload, 'id')
            });
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: false }
            });
            yield put({
                type: 'handleCheck',
                payload: {
                    callback: s.callback,
                    response
                }
            });
            // s.callback(response);
        },

        // 更新数据
        *[modelType.E_UPDATE_DATA](s, { select, call, put, all }) {
            const postData = yield* searchPostData(select, namespace);
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: true }
            });
            const response = yield call(updateData, {
                year: postData.year,
                month: postData.month,
                salaryPayrollIdList: _.map(s.payload, 'id'),
                organizationCode: postData.organizationCode
            });
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: false }
            });
            if (isSuccess(response)) {
                yield all([
                    put({ type: modelType.E_LOAD_STEP }),
                    put({ type: modelType.E_SEARCH })
                ]);
            } else {
                message.error(response.msg);
            }
            // eslint-disable-next-line no-unused-expressions
            s.callback && s.callback(response)
        },

        // 推迟下月发放
        *[modelType.E_POSTPONE_NEXT_MONTH](s, { call, select, put }) {
            const postData = yield* searchPostData(select, namespace);
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: true }
            });
            const response = yield call(postponeNextMonth, {
                year: postData.year,
                month: postData.month,
                organizationCode: postData.organizationCode,
                salaryPayrollIdList: _.map(s.payload, 'id')
            });
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: false }
            });
            s.callback(response);
        },

        // excel导出
        *[modelType.E_EXCEL_EXPORT](s, { select, call }) {
            const postData = yield* searchPostData(select, namespace);
            const state = yield* getState(select, namespace);
            postData.tableHeaderItemList = state.tableHeader;

            return yield call(excelExport, postData);
            // return yield call(excelExport, { ...postData, ...postData.searchModel, actionType: postData.nodeCode });
        },

        // 获取工资细项信息
        *[modelType.E_GET_SALARY_PAYROLL_ITEMS](s, { select, call, put }) {
            const currentRecord = yield select(state => state[namespace].currentRecord) || {};
            const response = yield call(getSalaryPayrollItems, currentRecord.id);

            if (!isSuccess(response)) {
                message.error(response.msg);
                return;
            }

            const items = response.data || [];
            yield put({
                type: modelType.SET_SALARY_PAYROLL_ITEMS,
                payload: items
            });
        },

        /**
         * 驳回细项初始化
         */ *[modelType.E_REJECT_INIT](s, { put }) {
            // 设置当前选择的数据 && 显示框出框
            yield put({
                type: modelType.SET_MULTI_STORE,
                payload: {
                    currentRecord: s.payload?.record ?? {},
                    modalVisible: s.payload.visible
                }
            });
        },
        /**
         * 单个驳回
         */
        *[modelType.E_REJECT](s, { put, select, call }) {
            const postData = yield* searchPostData(select, namespace);
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: true }
            });
            const response = yield call(reject, {
                ...s.payload,
                year: postData.year,
                month: postData.month,
                organizationCode: postData.organizationCode
            });
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: false }
            });

            if (!isSuccess(response)) {
                message.error(response.msg);
                return;
            }

            yield put({
                type: modelType.SET_MODAL_VISIBLE,
                payload: false
            });

            yield put({
                type: 'handleCheck',
                payload: {
                    callback: s.callback,
                    response
                }
            });
        },
        /**
         * 批量驳回
         */ *[modelType.E_BATCH_REJECT](s, { put, select, call }) {
            const postData = yield* searchPostData(select, namespace);

            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: true }
            });
            const response = yield call(batchReject, {
                year: postData.year,
                month: postData.month,
                organizationCode: postData.organizationCode,
                ...s.payload
            });
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: false }
            });

            if (!isSuccess(response)) {
                message.error(response.msg);
                return;
            }

            yield put({
                type: modelType.SET_MODAL_VISIBLE,
                payload: false
            });

            yield put({
                type: 'handleCheck',
                payload: {
                    callback: s.callback,
                    response
                }
            });
        },

        /**
         * 取消复核
         */ *[modelType.E_CANCEL_CHECK](s, { put, select, call }) {
            const postData = yield* searchPostData(select, namespace);

            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: true }
            });
            const response = yield call(cancelCheck, {
                salaryPayrollId: s.payload,
                year: postData.year,
                month: postData.month,
                organizationCode: postData.organizationCode
            });
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: false }
            });

             if (!isSuccess(response)) {
                message.error(response.msg);
                return;
             }

            yield put({
                type: 'handleCheck',
                payload: {
                    callback: s.callback,
                    response
                }
            });
        },

        /**
         * 复核通过
         */ *[modelType.E_PASS_CHECK](s, { put, select, call }) {
            const postData = yield* searchPostData(select, namespace);

            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: true }
            });
            const response = yield call(passCheck, {
                salaryPayrollId: s.payload,
                year: postData.year,
                month: postData.month,
                organizationCode: postData.organizationCode
            });
            yield put({
                type: modelType.SET_LOADING,
                payload: { tableLoading: false }
            });

            if (!isSuccess(response)) {
                message.error(response.msg);
                return;
            }
            yield put({
                type: 'handleCheck',
                payload: {
                    callback: s.callback,
                    response
                }
            });
        },
        /**
         * 所有按钮操作处理
         */
        *handleCheck(s, { put, all }) {
            if (!s.payload) {
                return;
            }
            const { callback, response } = s.payload;
            const { code, data } = response;

            if (code === 10000 && data && data.responseCode) {
                yield put({
                    type: 'articleWagesModel/openModal',
                    payload: {
                        articleWagesVisible: true,
                        articleWagesMsg: data.msg,
                        articleWagesPower: data.responseCode === 10000
                    }
                });
                return;
            }
            if (isSuccess(response)) {
                yield all([
                    put({ type: modelType.E_LOAD_STEP }),
                    put({ type: modelType.E_SEARCH })
                ]);
            }
            // eslint-disable-next-line no-unused-expressions
            callback && callback(response);
        },
        /**
         * 为了让stepList加载
         */
        *[modelType.E_LOAD_STEP](s, { put, call }) {
            yield put({
                type: modelType.SET_MULTI_STORE,
                payload: { stepLoading: true }
            });
            // 延迟10ms
            yield call(delay, 10);
            yield put({
                type: modelType.SET_MULTI_STORE,
                payload: { stepLoading: false }
            });
        }

    }
});

export default recheckModel;
